package uk.ac.lkl.lpp.ui;



//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import java.awt.event.FocusAdapter;
//import java.awt.event.FocusEvent;
import java.util.Map;

//import javax.swing.JTextField;

import uk.ac.lkl.lpp.model.PedagogyPlanModel;

import uk.ac.lkl.lpp.model.ldo.TeachingMethod;


/**
 * A view of a teaching method that uses its title as a label.
 * 
 * @author Darren Pearce
 * @version $Revision$
 * @version $Date$
 * 
 */
public class GroupSizeTeachingMethodView extends TextFieldTeachingMethodView {
	private static final long serialVersionUID = 1L;

    private Map<TeachingMethod, Integer> groupSizeMap;


    public GroupSizeTeachingMethodView(TeachingMethod teachingMethod,
            PedagogyPlanModel pedagogyPlanModel) {
        super(teachingMethod, pedagogyPlanModel);
        groupSizeMap = getPedagogyPlanModel().getMap(
                                                     "TeachingMethodGroupSize",
                                                     TeachingMethod.class,
                                                     Integer.class);
    }


    public void updateView() {
        TeachingMethod model = getModel();
        if (model == null) {
            setValue("");
            return;
        }
        Integer groupSize = groupSizeMap.get(model);
        if (groupSize == null)
            setValue("");
        else
            setValue(groupSize.toString());
    }


    protected boolean doProcessValue() {
        try {
            String stringValue = getValue();
            Integer value = Integer.parseInt(stringValue);
            groupSizeMap.put(getModel(), value);
            return true;
        }
        catch (NumberFormatException e) {
            return false;
        }
    }

}
